<template>
  <div class="success-container">
    <div class="success-card">
      <div class="success-icon">
        <i class="fas fa-check-circle"></i>
      </div>
      <h1 class="success-title">支付成功</h1>
      <p class="success-message">您的订单已支付成功，我们会尽快为您发货</p>
      <div class="order-info">
        <p>订单号：{{ orderId }}</p>
        <p>支付金额：¥{{ totalPrice.toFixed(2) }}</p>
      </div>
      <div class="action-buttons">
        <button class="view-order-btn" @click="goToOrders">
          查看我的订单
        </button>
        <button class="continue-shopping-btn" @click="goToHome">
          继续购物
        </button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'

const router = useRouter()
const route = useRoute()

const orderId = ref('')
const totalPrice = ref(0)

onMounted(async () => {
  // 从路由参数中获取订单信息
  if (route.params.orderNo) {
    orderId.value = route.params.orderNo;
    totalPrice.value = parseFloat(route.params.totalAmount) || 0;
    
    // try {
    //   // 调用支付成功回调接口
    //   const response = await paySuccess(orderId.value);
    //   if (response.code === 1) {
    //     ElMessage.success('支付成功');
    //   } else {
    //     ElMessage.error(response.msg || '支付失败');
    //   }
    // } catch (err) {
    //   console.error('支付回调处理失败:', err);
    //   ElMessage.error('支付回调处理失败');
    // }
  }
})

const goToOrders = () => {
  router.push('/orders')
}

const goToHome = () => {
  router.push('/')
}
</script>

<style scoped>
.success-container {
  max-width: 600px;
  margin: 60px auto;
  padding: 20px;
}

.success-card {
  background: white;
  border-radius: 12px;
  padding: 40px;
  text-align: center;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
}

.success-icon {
  font-size: 64px;
  color: #4CAF50;
  margin-bottom: 20px;
}

.success-title {
  font-size: 28px;
  color: #2c3e50;
  margin-bottom: 15px;
}

.success-message {
  color: #666;
  margin-bottom: 30px;
}

.order-info {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 30px;
}

.order-info p {
  margin: 10px 0;
  color: #666;
}

.action-buttons {
  display: flex;
  gap: 20px;
  justify-content: center;
}

.view-order-btn, .continue-shopping-btn {
  padding: 12px 30px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
}

.view-order-btn {
  background: #4CAF50;
  color: white;
  border: none;
}

.view-order-btn:hover {
  background: #45a049;
  transform: translateY(-2px);
}

.continue-shopping-btn {
  background: white;
  color: #666;
  border: 1px solid #ddd;
}

.continue-shopping-btn:hover {
  background: #f8f9fa;
  transform: translateY(-2px);
}

@media (max-width: 768px) {
  .success-container {
    margin: 30px auto;
  }

  .success-card {
    padding: 30px 20px;
  }

  .action-buttons {
    flex-direction: column;
  }

  .view-order-btn, .continue-shopping-btn {
    width: 100%;
  }
}
</style> 